#include <spi.h>

void spi_init(void)
{
		CMU_ClockEnable(cmuClock_USART2, true);
		GPIO_PinModeSet(gpioPortC, 2, gpioModePushPull, 0);              //set PC2 -> US2_TX  pushpull  default: Low
    GPIO_PinModeSet(gpioPortC, 3, gpioModeInput, 0);                 //set PC3 -> US2_RX  input     default: Low
    GPIO_PinModeSet(gpioPortC, 4, gpioModePushPull, 0);              //set PC4 -> SPI_CLK pushpull  default: Low
	  GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 1);              //set PEC1 -> SPI_CS  pushpull default: High
    GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);              //set PC0 ->EEPROM_WP#		
	
		USART_InitSync_TypeDef spiStructure = USART_INITSYNC_DEFAULT;  
    spiStructure.msbf = true;
    spiStructure.baudrate = 1000000;
    USART_InitSync(USART2, &spiStructure);
    
    USART_IntClear(USART2, _USART_IFC_MASK);
    NVIC_ClearPendingIRQ(USART2_RX_IRQn);
    USART2->ROUTE = USART_ROUTE_RXPEN | USART_ROUTE_TXPEN  | USART_ROUTE_CLKPEN  | USART_ROUTE_LOCATION_DEFAULT;   //set  use usart0_0 channel        

}
